/**
 * 用户组列表返回数据实体
 */
interface UserGroupListItemResponse {
    /**
     * 主键
     */
    id: string;
    /**
     * 索引
     */
    index: number;
    /**
     * 用户组名称
     */
    name: string;
    /**
     * 权限数
     */
    authorizationCount: number;
    /**
     * 用户数
     */
    userCount: number;

    middleAuthNumber:string;
    highAuthNumber:string;
    lowAuthNumber:string;
    secAuthorizationTypeTag:string[]


}

/**
 * 用户组详细
 */
interface UserGroupDetailResponse extends BaseResponse {
    /**
     * 用户组名称
     */
    name: string;
    /**
     * 用户组权限
     */
    roles: Array<string>;

    /**
     * 专员类型组
     */
    commissionerType: Array<string>;
}

/**
 * 用户组权限
 */
interface  UserGroupAuth {
    //高等级权限
    HighAuthNumber:number[];
    //中等级权限
    MiddleAuthNumber:number[];
    //低等级权限
    LowAuthNumber:number[];
    //二级权限标签
    SecAuthTypeTag:string[]
}

/**
 * 用户组服务
 */
interface IUserGroupService {
    /**
     * 获取用户组列表
     * v1.0
     * @param name 用户组名称
     * @param skip 跳过项数
     * @param count 获取项数
     */
    getList(name: string, skip: number, count: number,logisticsCompanyId?:string): ng.IHttpPromise<ListResponse<UserGroupListItemResponse>>;

    /**
     * 获取用户组详细
     * v1.0
     * @param id 用户组编号
     */
   getDetail(id: string): ng.IHttpPromise<UserGroupDetailResponse>;

    /**
     * 添加用户组
     * v1.0
     * @param name 用户组名称
     * @param roles 用户组权限
     * @param roles 权限组
     */
    add(name: string, roles: Array<string>): ng.IHttpPromise<BaseResponse>;

    /**
     * 编辑用户组
     * v1.0
     * @param id 用户组编号
     * @param name 用户组名称
     * @param roles 用户组权限
     * @param roles 权限组
     */
    edit(id: string, name: string, roles: Array<string>): ng.IHttpPromise<BaseResponse>;

    /**
     * 删除用户组
     * v1.0
     * @param id 用户组编号
     */
    delete(id: string): ng.IHttpPromise<BaseResponse>;

    /**
     * 编辑用户组权限
     * v1.0
     * @param id 用户组编号
     * @param body 权限
     */
    editAuth:(id:string,body:UserGroupAuth)=>ng.IHttpPromise<BaseResponse>;
}

class userGroupService implements IUserGroupService {
    constructor(private http: ng.IHttpService, private route: routeService) {
    }

    getList(name: string, skip: number, count: number,logisticsCompanyId?:string): ng.IHttpPromise<ListResponse<UserGroupListItemResponse>> {
        return this.http<ListResponse<UserGroupListItemResponse>>({
            method: "GET",
            url: this.route.getUrl("userGroup?name={{name}}&skip={{skip}}&count={{count}}&logisticsCompanyId={{logisticsCompanyId}}", {
                name: name,
                skip: skip,
                count: count,
                logisticsCompanyId:logisticsCompanyId
            })
        });
    }

    getDetail(id: string): ng.IHttpPromise<UserGroupDetailResponse> {
        return this.http<UserGroupDetailResponse>({
            method: "GET",
            url: this.route.getUrl("userGroup/{{id}}", {
                id: id
            })
        });
    }

    add(name: string, roles: Array<string>): ng.IHttpPromise<BaseResponse> {
        return this.http<BaseResponse>({
            method: "POST",
            url: this.route.getUrl("userGroup"),
            data: {
                name: name,
                roles: roles
            }
        });
    }

    edit(id: string, name: string, roles: Array<string>): ng.IHttpPromise<BaseResponse> {
        return this.http<BaseResponse>({
            method: "PUT",
            url: this.route.getUrl("userGroup/{{id}}", {
                id: id
            }),
            data: {
                name: name,
                roles: roles
            }
        });
    }

    delete(id: string): ng.IHttpPromise<BaseResponse> {
        return this.http<BaseResponse>({
            method: "DELETE",
            url: this.route.getUrl("userGroup/{{id}}", {
                id: id
            })
        });
    }
    /**编辑权限 */
    editAuth(id:string,body:UserGroupAuth):ng.IHttpPromise<BaseResponse>{
        return this.http<BaseResponse>({
            method:"PUT",
            url:this.route.getUrl("userGroup/SaveUserGroupAuth?id={{id}}",{id:id}),
            data:body
        })
    }

}

angular.module("userGroupService",[]).service("userGroupService",['$http','routeService',userGroupService]);